/**
 * @file      ac_tlm_lock.h
 * @author    Grupo 04
 * 
 */

//////////////////////////////////////////////////////////////////////////////

#ifndef AC_TLM_LOCK_H
#define AC_TLM_LOCK_H

//////////////////////////////////////////////////////////////////////////////

// Standard includes
// SystemC includes
#include <systemc>
// ArchC includes
#include "ac_tlm_protocol.H"

//////////////////////////////////////////////////////////////////////////////

// using statements
using tlm::tlm_transport_if;

//////////////////////////////////////////////////////////////////////////////

#define ADDR_BASE (5*1024*1024+20)
#define NUM_LOCKS 100


/// Namespace to isolate memory from ArchC
namespace user
{

class ac_tlm_lock :
  public sc_module,
  public ac_tlm_transport_if // Using ArchC TLM protocol
{
public:

  /// Exposed port with ArchC interface
  sc_export< ac_tlm_transport_if > target_export;
  /// Internal write
  ac_tlm_rsp_status writem( const uint32_t & );
  /// Internal read
  ac_tlm_rsp_status readm( const uint32_t & , uint32_t & );
  
  /**
   * Implementation of TLM transport method that
   * handle packets of the protocol doing apropriate actions.
   * This method must be implemented (required by SystemC TLM).
   * @param request is a received request packet
   * @return A response packet to be send
  */
  ac_tlm_rsp transport( const ac_tlm_req &request ) {

    ac_tlm_rsp response;

    switch( request.type ) {
    case READ :     // Packet is a READ one
      response.status = readm( request.addr , response.data );
      break; 
    case WRITE:     // Packet is a WRITE
      response.status = writem( request.addr );
      break;
    default :
      response.status = ERROR;
      break; 
    }

    return response;
  }


  /** 
   * Default constructor.
   * 
   */
  ac_tlm_lock( sc_module_name module_name );

private:
  uint8_t locks[NUM_LOCKS];

};

};

#endif //AC_TLM_LOCK_H
